﻿using System;
using DTcms.Common;
using DTcms.Cache.Factory;

namespace DTcms.BLL
{
    public partial class userconfig
    {
        private readonly DAL.userconfig dal = new DAL.userconfig();
        //缓存关键词及名称
        private const int cacheTime = 30;  //分钟
        private const string cacheString = DTKeys.CACHE_USER_CONFIG;

        /// <summary>
        /// 读取用户配置文件
        /// </summary>
        /// <param name="isCache">是否读取缓存</param>
        /// <returns></returns>
        public Model.userconfig loadConfig(bool isCache = true)
        {
            Model.userconfig model = new Model.userconfig();
            if (isCache)
            {
                model = CacheFactory.Cache().GetCache<Model.userconfig>(cacheString);
                if (model == null)
                {
                    model = dal.loadConfig(Utils.GetXmlMapPath(DTKeys.FILE_USER_XML_CONFING));
                    CacheFactory.Cache().WriteCache(model, cacheString, cacheTime);
                }
            }
            else
            {
                model = dal.loadConfig(Utils.GetXmlMapPath(DTKeys.FILE_USER_XML_CONFING));
            }
            return model;
        }

        /// <summary>
        ///  保存用户配置文件
        /// </summary>
        public Model.userconfig saveConifg(Model.userconfig model)
        {
            return dal.saveConifg(model, Utils.GetXmlMapPath(DTKeys.FILE_USER_XML_CONFING));
        }
    }
}